package com.zenika.zenbinding.client.model;

import com.google.gwt.user.client.ui.Widget;
import com.zenika.zenbinding.client.exception.DataMessage;
import com.zenika.zenbinding.client.feedback.FeedbackManager;
import com.zenika.zenbinding.client.handler.Handler;

/**
 * This interface is used to create Models which are adapters between the BusinessObject and a widget handler.
 * 
 * @author Zenika
 */
public interface Model {
  
  /**
   * Called when the model enter in the error state. It notifies the feedback manager.
   * 
   * @param message
   *          Message describing the error
   * @param handler
   *          Handler causing the error
   */
  public void fireError(DataMessage message, Handler handler);
  
  /**
   * Called when the model leave the error state. It notifies the feedback manager.
   * 
   * @param handler
   *          Handler that had caused the error
   */
  public void fireErrorStop(Handler handler);
  
  /**
   * Specify which feedback manager to use.
   * 
   * @param manager
   *          FeedbackManager
   */
  public void setFeedbackManager(FeedbackManager manager);
  
  /**
   * Specify which FeedbackManager to use and the identifier of the Model causing the error. The identifier is appended to the error message to point out the origin of the error.
   * 
   * @param manager
   * @param feedbackId
   */
  public void setFeedbackManager(FeedbackManager manager, String feedbackId);
  
  public Handler getHandler();
  
  public Widget getWidget();
  
  public DataMessage validate();
  
  public DataMessage getCurrentValidationState();
  
}
